﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using RPGXEngine;
using RPGX.Graphics;

namespace RPGX.Scripting.SystemFunctions
{
    public static class SystemFunction_HUDTextBoxGetText
    {
        public static IVariableType Method(ScriptManager sm, FunctionScope scope, List<IVariableType> data)
        {
            if (data == null || data.Count != 1)
                return sm.Zero;

            string text = String.Empty;

            IVariableType res = VariableTypeFactory.Create(DataType.Var, String.Empty, text);

            string id = data[0].Value.ToString();

            try
            {
                if (Game1.Instance.HUD.ObjectsById.ContainsKey(id))
                {
                    HUDObject_TextBox tb = Game1.Instance.HUD.ObjectsById[id] as HUDObject_TextBox;
                    if (tb != null)
                    {
                        text = tb.Text;

                        res.SetValue(text.Trim());
                    }
                }
            }
            catch (Exception)
            {
                res = sm.False;
            }

            return res;
        }
    }
}
